<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="org.racsor.cc.model.RequestCC" %>
<%@ page import="org.racsor.cc.model.PMF" %>
<%@ page import="com.google.appengine.api.blobstore.BlobstoreServiceFactory" %>
<%@ page import="com.google.appengine.api.blobstore.BlobstoreService" %>

<%
    BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
%>

<html>
  <head>
    <link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
  </head>

  <body>


<%
    PersistenceManager pm = PMF.get().getPersistenceManager();
    String query = "select from " + RequestCC.class.getName() + " order by date desc range 0,5";
    List<RequestCC> requests = (List<RequestCC>) pm.newQuery(query).execute();
    if (requests.isEmpty()) {
%>
<p>The guestbook has no messages.</p>
<%
    } else {
        for (RequestCC g : requests) {
            if (g.getAuthor() == null) {
%>
<p>An anonymous person wrote:</p>
<%
            } else {
%>
<p><b><%= g.getAuthor().getNickname() %></b> wrote:</p>
<%
            }
%>
<blockquote><%= g.getId() %></blockquote>
<blockquote><%= g.getDate() %></blockquote>
<blockquote><%= g.getUrl() %></blockquote>
<blockquote><%= g.getParameters() %></blockquote>
<%
        }
    }
    pm.close();
%>

<form action="<%= blobstoreService.createUploadUrl("/saveRequest") %>" method="post" enctype="multipart/form-data">
      <div><input type="text" name="url"></div>
      <div><input type="text" name="parameters"></div>
      <div><input type="file" name="myFile"></div>
      <div><input type="submit" value="Post Greeting" /></div>
    </form>

  </body>
</html>